package hw06;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class hw3 {

	public static void main(String[] args) throws Exception {
		File file = new File("E:\\AAA\\BBB");
		File aimFile = new File("E:\\AAA\\aimFile");

		copy(file, aimFile);
	}

	private static void copy(File file, File aimFile) throws IOException {
		
		aimFile.mkdirs();
		// bianli
		File[] files = file.listFiles();
		for (File file1 : files) {
			if (file.isFile()) {
				FileInputStream fis = new FileInputStream(file);
				FileOutputStream fos = new FileOutputStream(new File(aimFile, file.getName()));
				byte[] bytes = new byte[1024];
				int len = 0;
				while ((len = fis.read(bytes)) != -1) {
					fos.write(bytes, 0, len);
				}
				fos.close();
				fis.close();
			} else {
				copy(file, new File(aimFile, file.getName()));
			}
		}
	}

}
